Step 5: The Driver Code

You've built the class! Now, just write the main script to read the $N$ commands and call your methods.

Guidance for Step 5

  • This part is about string parsing and calling the object methods you just wrote.
  • Create an instance of your PriorityQueue.
  • Read n, then loop n times.
  • Remember to convert k to an int for the push operation.
  • The blanks are for calling the correct method on your pq object.
# (Make sure your class definition is above this)

# Create a new Priority Queue
pq = PriorityQueue()

# Read the number of operations
n = int(input().strip())

# Process each operation
for _ in range(n):
    line = input().strip().split()
    cmd = line[0]

    if cmd == "push":
        k = int(line[1])
        ________  # Call the push method
    elif cmd == "peek":
        print(________)  # Call the peek method
    elif cmd == "pop":
        print(________)  # Call the pop method

                
Copied!